package cm.tl.pms.common.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * 注解处理器
 *
 * @author w7h1te_ywq
 * @version 1.0.0
 * @date 2023-11-03 15:50
 */
@Component
@Aspect
@Order(2)
public class DuplicateRequestCheckHandler {

    public static final Logger logger = LoggerFactory.getLogger(DuplicateRequestCheckHandler.class.getName());

    @Around("@annotation(cm.tl.pms.annotation.DuplicateRequestCheck)")
    public Object checkAndRecordDuplicateRequest(ProceedingJoinPoint joinPoint) throws Throwable {
        logger.info("------------  进入  (checkAndRecordDuplicateRequest) 切面处理  校验业务单次唯一requestId ");
        Object[] args = joinPoint.getArgs();
        if (args != null && args.length > 0) {
            for (Object arg : args) {
//                if (arg instanceof ChainBaseInfo) {
//                    ChainBaseInfo request = (ChainBaseInfo) arg;
//                    logger.info("------------ requestId: "+ request.getRequestId());
//                    // 判断请求是否已经处理过
//                    if (DuplicateRequestValidator.isDuplicateRequest(request.getRequestId())) {
//                        return ResultRsp.failResult(ErrorEnum._20005);
//                    }
//                    // 处理请求并记录请求ID
//                    DuplicateRequestValidator.recordRequestId(request.getRequestId());
//                }
            }
        }
        // 调用原方法
        return joinPoint.proceed();
    }

}
